/* ========================================================================= */
/* ------------------------------------------------------------------------- */
/*!
  \file			mdiimpl.h
  \date			Dec 2012
  \author		TNick

  \brief		Contains the definition for MdiImpl class


*//*


 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 Please read COPYING and README files in root folder
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
/* ------------------------------------------------------------------------- */
/* ========================================================================= */
#ifndef __MDIIMPL_INC__
#define __MDIIMPL_INC__
//
//
//
//
/*  INCLUDES    ------------------------------------------------------------ */

#include	<memtrack.h>
#include	<cpg/actions/editorbase.h>
#include	<QObject>
#include	<ui_mdi.h>


/*  INCLUDES    ============================================================ */
//
//
//
//
/*  CLASS    --------------------------------------------------------------- */

class	ActionsHost;
class	QMenu;
class	QToolBar;
class	QMdiSubWindow;
class	QMdiArea;
class	MdiContainer;

/**
*	@brief
*/
class MdiImpl				: public QObject, public MemTrack	{
	Q_OBJECT
	BBM_TRACK( MdiImpl )

	//
	//
	//
	//
	/*  DEFINITIONS    ----------------------------------------------------- */

	/*  DEFINITIONS    ===================================================== */
	//
	//
	//
	//
	/*  DATA    ------------------------------------------------------------ */

private:

	/**
	*	@brief
	*/
	Ui::Mdi			ui_;


	/**
	*	@brief	the host
	*/
	ActionsHost *		host_;


	/**
	*	@brief	the host
	*/
	QMdiArea *			mdi_area_;


	/*  DATA    ============================================================ */
	//
	//
	//
	//
	/*  FUNCTIONS    ------------------------------------------------------- */

public:


	/**
	*	@brief	constructor;
	*/
	MdiImpl				( QObject * parent = NULL );


	/**
	*	@brief	destructor;
	*/
	virtual				~MdiImpl			( void );


	/**
	*	@brief	initialisation
	*/
	bool				init				(
			ActionsHost *			host,
			QMdiArea *				mdi_area
			);


	/**
	*	@brief	termination
	*/
	void				end					( void );


	/**
	*	@brief	inserts the actions in the menu
	*/
	void				initMenu			( QMenu * menu );


	/**
	*	@brief	the target editor
	*/
	EditorBase *		crtEditor			( void );


	/**
	*	@brief	the container mdi is being closed
	*/
	bool				closeEvent			( MdiContainer * container );


	/**
	*	@brief	get the EditorBase that coresponds to a widget
	*/
	EditorBase *		editorForObject		( QObject * w );


public slots:


	/**
	*	@brief	recieved when a new document editor is created
	*
	*	This slot creates the infrastructure for this new editor
	*/
	void				editorCreated				( EditorBase * ed );


	/**
	*	@brief	recieved when a document editor should be closed
	*
	*	The user can still cancel the process.
	*/
	bool				editorCloseReq				( EditorBase * ed );


	/**
	*	@brief	recieved when a document should be saved
	*
	*	Uses standard dialogs to ask the user for a location
	*/
	bool				editorSaveAsReq				( EditorBase * ed );


	/**
	*	@brief	recieved when a document should be saved
	*
	*	If the document is untitled asks editorSaveAsReq() to save it, otherwise
	*	it saves the document.
	*/
	bool				editorSaveReq				( EditorBase * ed );


	/**
	*	@brief	save all documents
	*/
	bool				closeAll					( void );


	/**
	*	@brief	save all documents
	*/
	bool				slot_SaveAll				( void );


signals:


	/**
	*	@brief	an editor is being closed
	*
	*	At this point the process is irreversible.
	*/
	void				editorClosing				( EditorBase * ed );


	/**
	*	@brief	the content in an editor was saved to disk
	*/
	void				editorSaved					( EditorBase * ed );


	/**
	*	@brief	current editor changed; may be NULL.
	*/
	void				activeEditorChanged			( EditorBase * ed );


	/**
	*	@brief	a request to open a local file is issued from an editor
	*/
	void				openFileUReq				(
			const QString & s_path,
			const QString & loc
			);


	/**
	*	@brief	a request to open an external resource from an editor
	*/
	void				openLinkUReq				( const QUrl & url );



private slots:


	/**
	*	@brief	informed when active document has changed
	*/
	void				slot_ActiveMdiChange		( QMdiSubWindow * p_active );


	/**
	*	@brief	used by the windows menu to change active document
	*/
	void				slot_ActiveMdiChange		( QAction * p_active );


	/**
	*	@brief	informed that a file was created/opened as an output file
	*/
	void				outputFileOpened			( const QString & s );


private:


	/**
	*	@brief	recreates the list of windows currently opened in MDI
	*/
	void				slot_UpdateWinMenu			(void);


	/**
	*	@brief	editor was saved
	*/
	void				slot_editorSaved			( EditorBase * ed );


	/**
	*	@brief	called when a document editor should be closed
	*
	*	The user can still cancel the process.
	*/
	bool				editorCloseReqInternal		( EditorBase * ed );



	/*  FUNCTIONS    ======================================================= */
	//
	//
	//
	//

};	/*	class MdiImpl	*/

/*  CLASS    =============================================================== */
//
//
//
//
#endif // __MDIIMPL_INC__
/* ------------------------------------------------------------------------- */
/* ========================================================================= */
